﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Engine.Entities.Character
{

    public class Skills
    {
        public const int NUMBER_OF_SKILLS = 6;
        public const int VALUE_DEFAULT = 10;

        public Dictionary<SkillsEnum, int> ValueSkill { get; set; }

        public Skills()
        {
            ValueSkill = new Dictionary<SkillsEnum, int>();

            SetSkill(SkillsEnum.Intelligence, VALUE_DEFAULT);
            SetSkill(SkillsEnum.Resistance, VALUE_DEFAULT);
            SetSkill(SkillsEnum.Strenght, VALUE_DEFAULT);
            SetSkill(SkillsEnum.Agility, VALUE_DEFAULT);
            SetSkill(SkillsEnum.Charm, VALUE_DEFAULT);
            SetSkill(SkillsEnum.Appeal, VALUE_DEFAULT);
        }

        public Skills(int Int, int Res, int Str, int Agl, int Cha, int App)
        {
            ValueSkill = new Dictionary<SkillsEnum, int>();
            SetSkill(SkillsEnum.Intelligence, Int);
            SetSkill(SkillsEnum.Resistance, Res);
            SetSkill(SkillsEnum.Strenght, Str);
            SetSkill(SkillsEnum.Agility, Agl);
            SetSkill(SkillsEnum.Charm, Cha);
            SetSkill(SkillsEnum.Appeal, App);
        }

        //public void ClearSkill()
        //{
        //    foreach (SkillsEnum item in ValueSkill.Keys) SetSkill(item, 0);
        //}

        internal int GetValue(SkillsEnum skill)
        {
            return ValueSkill[skill];
        }

        public static SkillsEnum GetTypeSkill(int index)
        {
            switch (index)
            {
                case 0: return SkillsEnum.Intelligence;
                case 1: return SkillsEnum.Resistance;
                case 2: return SkillsEnum.Strenght;
                case 3: return SkillsEnum.Agility;
                case 4: return SkillsEnum.Charm;
                case 5: return SkillsEnum.Appeal;
            }
            throw new IndexOutOfRangeException("GetTypeSkill");
        }

        public override string ToString()
        {
            string ris = "";
            foreach (SkillsEnum skill in SkillsEnum.GetValues(typeof(SkillsEnum)))
            {
                ris += skill.ToString().Substring(0, 3) + ": " + GetValue(skill) + " ";
            }
            return ris;
        }

        /// <summary>
        ///     Funzione usata solo nel costruttore della skill
        ///     Attenzione!!!
        ///     Questa funzione non aggiurnerà eventualmente i metadati
        /// </summary>
        /// <param name="skill"></param>
        /// <param name="value"></param>
        private void SetSkill(SkillsEnum skill, int value)
        {
            int prec = value;

            if (ValueSkill.ContainsKey(skill) == false)
                ValueSkill.Add(skill, value);
            else
                ValueSkill[skill] = value;
        }

    }
}